var t = u(require("../../../../@babel/runtime/regenerator")),
  e = require("../../../../@babel/runtime/helpers/asyncToGenerator"),
  a = u(require("../../../../config/index")),
  n = u(require("../../../../config/page")),
  r = require("../../../../utils/jump"),
  i = require("@/services/base/api"),
  s = require("@/services/user-service");
function u(t) {
  return t && t.__esModule ? t : { default: t };
}
var o = 0;
Page({
  data: {
    CDN: a.default.CDN,
    COMPLAINT_STATUS: { 1: "待回复", 2: "已处理" },
    list: [],
    activeList: [],
    titles: ["投诉", "建议"],
    objs: [
      "无",
      "其他",
      "服务问题",
      "设施问题",
      "展览问题",
      "环境问题",
      "票务问题",
    ],
    navBarHeight: 0,
    comQuery: { rn: 10, pn: 1 },
    advQuery: { rn: 10, pn: 1 },
    titleIndex: 0,
    swiperCurrent: 0,
    comlastPage: !1,
    advlastPage: !1,
    height: 0,
    swiperTop: 0,
  },
  onLoad: function () {
    var a = this;
    return e(
      t.default.mark(function e() {
        var n, r;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                (n = a.createSelectorQuery().in(a))
                  .select("#exhTitle")
                  .boundingClientRect(),
                  (r = new Date().getTime()),
                  n.exec(function (t) {
                    o = t[0].height;
                    var e = getApp().globalSystemInfo,
                      n = e.navBarHeight;
                    e.ios && (n += e.navBarExtendHeight);
                    var i = wx.getSystemInfoSync().windowHeight - n - o;
                    a.setData({
                      height: i,
                      swiperTop: o,
                      navBarHeight: n,
                      times: r,
                    });
                  });
              case 4:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  onShow: function () {
    this.getList(), this.getActiveList();
  },
  getList: function () {
    var a = this;
    return e(
      t.default.mark(function e() {
        var n, r, u, o, l, c, d, v;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                return (u = ""), (t.next = 3), (0, s.getUserId)();
              case 3:
                return (
                  (u = t.sent),
                  (o = { pn: 1, rn: 10, open_id: u }),
                  (t.next = 7),
                  (0, i.postComplaintList)(o)
                );
              case 7:
                (l = t.sent),
                  (c =
                    null != l &&
                    null !== (n = l.data) &&
                    void 0 !== n &&
                    n.total
                      ? l.data.total
                      : 0),
                  (d =
                    null != l && null !== (r = l.data) && void 0 !== r && r.list
                      ? l.data.list
                      : []),
                  a.setData({ list: d, "comQuery.pn": 2 }),
                  (v = a.data.list),
                  a.setData({ comlastPage: v.length >= c }),
                  console.log(l);
              case 14:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  changeTitle: function (a) {
    var n = this;
    return e(
      t.default.mark(function e() {
        var r;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                (r = a.currentTarget.dataset.index),
                  n.setData({ titleIndex: r, swiperCurrent: r }),
                  0 === Number(r)
                    ? n.getList()
                    : 1 === Number(r) && n.getActiveList();
              case 3:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  changeCurrent: function (t) {
    var e = t.detail.current;
    this.setData({ titleIndex: e, swiperCurrent: e }),
      0 === e ? this.getList() : 1 === e && this.getActiveList();
  },
  getActiveList: function () {
    var a = this;
    return e(
      t.default.mark(function e() {
        var n, r, u, o, l, c, d, v;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                return (u = ""), (t.next = 3), (0, s.getUserId)();
              case 3:
                return (
                  (u = t.sent),
                  (o = { pn: 1, rn: 10, open_id: u }),
                  (t.next = 7),
                  (0, i.postAdviceList)(o)
                );
              case 7:
                (l = t.sent),
                  (c =
                    null != l &&
                    null !== (n = l.data) &&
                    void 0 !== n &&
                    n.total
                      ? l.data.total
                      : 0),
                  (d =
                    null != l && null !== (r = l.data) && void 0 !== r && r.list
                      ? l.data.list
                      : []),
                  a.setData({ activeList: d, "advQuery.pn": 2 }),
                  (v = a.data.activeList),
                  a.setData({ advlastPage: v.length >= c });
              case 13:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  toDetail: function (t) {
    console.log(t, "item");
    var e = t.currentTarget.dataset,
      a = e.status,
      i = e.item;
    if (1 === Number(a)) {
      console.log(i);
      var s = i.complaint_id;
      (0, r.navigateTo)(n.default.PAGE_COMPLAINT_DETAIL, { status: a, id: s });
    } else {
      var u = i.id;
      (0, r.navigateTo)(n.default.PAGE_COMPLAINT_DETAIL, { status: a, id: u });
    }
  },
  toCreateComplaint: function () {
    (0, r.navigateTo)(n.default.PAGE_COMPLAINT_CREATE, {
      source: "list",
      status: "1",
    });
  },
  toCreateAdvice: function () {
    (0, r.navigateTo)(n.default.PAGE_COMPLAINT_CREATE, {
      source: "list",
      status: "2",
    });
  },
  onComBottomFunc: function () {
    this.getMoreList();
  },
  onAdvBottomFunc: function () {
    this.getMoreActiveList();
  },
  getMoreList: function () {
    var a = this;
    return e(
      t.default.mark(function e() {
        var n, r, u, o, l, c, d, v, p;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                if (!a.data.comlastPage) {
                  t.next = 2;
                  break;
                }
                return t.abrupt("return");
              case 2:
                return (
                  (u = a.data.comQuery),
                  (o = ""),
                  (t.next = 6),
                  (0, s.getUserId)()
                );
              case 6:
                return (
                  (o = t.sent),
                  (l = { pn: u.pn, rn: u.rn, open_id: o }),
                  (t.next = 10),
                  (0, i.postComplaintList)(l)
                );
              case 10:
                (c = t.sent),
                  (d =
                    null != c &&
                    null !== (n = c.data) &&
                    void 0 !== n &&
                    n.total
                      ? c.data.total
                      : 0),
                  (v =
                    null != c && null !== (r = c.data) && void 0 !== r && r.list
                      ? c.data.list
                      : []),
                  a.setData({
                    list: a.data.list.concat(v),
                    "comQuery.pn": u.pn + 1,
                  }),
                  (p = a.data.list),
                  a.setData({ comlastPage: p.length >= d });
              case 16:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  getMoreActiveList: function () {
    var a = this;
    return e(
      t.default.mark(function e() {
        var n, r, u, o, l, c, d, v, p;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                if (!a.data.advlastPage) {
                  t.next = 2;
                  break;
                }
                return t.abrupt("return");
              case 2:
                return (
                  (u = a.data.advQuery),
                  (o = ""),
                  (t.next = 6),
                  (0, s.getUserId)()
                );
              case 6:
                return (
                  (o = t.sent),
                  (l = { pn: u.pn, rn: u.rn, open_id: o }),
                  (t.next = 10),
                  (0, i.postAdviceList)(l)
                );
              case 10:
                (c = t.sent),
                  (d =
                    null != c &&
                    null !== (n = c.data) &&
                    void 0 !== n &&
                    n.total
                      ? c.data.total
                      : 0),
                  (v =
                    null != c && null !== (r = c.data) && void 0 !== r && r.list
                      ? c.data.list
                      : []),
                  a.setData({
                    activeList: a.data.activeList.concat(v),
                    "advQuery.pn": u.pn + 1,
                  }),
                  (p = a.data.activeList),
                  a.setData({ advlastPage: p.length >= d }),
                  console.log(c);
              case 17:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
});
